package com.apptonelabs.android.controller;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ListView;
import android.widget.Toast;

import com.apptonelabs.android.model.PNRStatus;
import com.apptonelabs.android.model.PNRStatusList;
import com.apptonelabs.android.model.PNRType;
import com.apptonelabs.android.view.PNRArrayAdapter;

public class PNRListActivity extends ListActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		// No title bar
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		PNRType type = (PNRType) getIntent().getExtras().getSerializable("pnrlisttype");
		PNRStatusList obj = (PNRStatusList) getIntent().getExtras().getSerializable("pnrlist");
		
		List<PNRStatus> values = new ArrayList<PNRStatus>();
		
		// Position == 0 should be the Header/title
		values.add(new PNRStatus());
		
		// Insert the List at the end
		values.addAll(obj.getList());
		
		setListAdapter(new PNRArrayAdapter(this, values, type));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// get selected items
		String selectedValue = (String) getListAdapter().getItem(position);
		Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
	}
}